function list_admin_init() {
	getParentDep(); //大部门信息
	if(typeof(parentdep) != 'undefined')
	{
		getSubDep(parentdep);
	}
	//管理员列表删除按钮
	$(".btn_remove").click(function() {
			var link = $(this);
			var act = $(this).attr("act");
			var msg = '';
			if(act == 'del'){
				msg = '确定删除管理员？';
			}
			else{
				msg = '确定恢复？';
			}
			$("#confirm_div_text").text(msg);
			$("#confirm_div").showMiddleDialog(["confirm_close", "confirm_ok", "confirm_cancel"], function() {
				if ($(this).attr("id") != "confirm_ok") {
					return;
				}

				var rel = link.attr("rel");
				$.post("/admin/del.php", "action="+act+"&staff=" + rel, function(json) {
					if (json.status == 1) {
						window.location.reload();
					} else {
						$("#confirm_div_text").text(json.msg);
						$("#confirm_div").showMiddleDialog(["confirm_close", "confirm_ok", "confirm_cancel"]);
					}
					}, "json");
				});
	});

	//添加管理员的全选，反选
	$(".sel_btn").click(function(){
				var rel = $(this).attr("rel");
				var type = $(this).attr("type");	//type=1 全选 type=2返选
				rel = "bigclass_"+rel;	//当前要选的id下的所有checkbox
				if(type == 1){
					$("#"+rel).find("input[name='power[]']").attr("checked", true); 
				}
				else{
					$("#"+rel).find("input[name='power[]']").each(function(){
						$(this).attr("checked") == true ? $(this).attr('checked', false) : $(this).attr('checked', true);
						}); 
				}
			});
	
	//搜索
	$("#admin_search_type").click(function(){
		obj = $("#admin_search_value");
		if (obj.val() == '') {
			alert("查询关键字不能为空！");
			return false;
		}
		$("#admin_search_type_form").submit();
	});
	//部门搜索
	$("#admin_search_dep").click(function(){
		$("#admin_search_dep_form").submit();
	});
	//取staff的部门信息展示
	$("#showstaff").click(function(){
		$("#staffdetail").fadeOut();
		$("#staffphone").fadeOut();
		var staff  = $("input:[name='staff']").val();
		if(!$.trim(staff)){
			return false;
		}
		$.get("/aj_staff.php?staff="+staff, "", function(rs){
			var _msg = eval("("+rs+")");
			if(!_msg.error){
				$("#staffphone").fadeIn();
				$("input:[name='phone']").val(_msg.phone);
				$("#staffdetail").html();
				tmp = "<font color=green>姓名    </font>："+_msg.name+"&nbsp;&nbsp;&nbsp;";
				tmp +="<font color=green>分机：</font>"+_msg.phone+"&nbsp;&nbsp;&nbsp;";
				tmp +="<font color=green>手机：</font>"+_msg.mobile+"&nbsp;&nbsp;&nbsp;";
				tmp +="<font color=green>部门：</font>"+_msg.subdep+"&nbsp;&nbsp;&nbsp;";
				tmp +="<font color=green>地区：</font>"+_msg.area+"&nbsp;&nbsp;&nbsp;";
				$("#staffdetail").html("<th>&nbsp;</th><td>"+tmp+"</td>");
				$("#staffdetail").fadeIn();
			}else{
				$("#staffdetail").html("<th>&nbsp;</th><td>"+_msg.msg+"</td>");
				$("#staffdetail").fadeIn();
			}
		});
	})
	$("#parentdep").change(function(){
		var curv = $(this).val();
		getSubDep(curv);
	});
    //显示隐藏 #@sina# 及密码框
    $("#atsina").click(function(){
        if(this.checked) {
            $(".showsina").show();
            return;
        }
        $(".showsina").hide();
    });
}
function getSubDep(pid){
	$.post("/aj_staff.php?action=getsubdep&pid="+pid,"",function(rs){
		var subdep = eval("("+rs+")");
		$("#subdep").html("");
		var op = "<option value=-1>小部门</option>";
		if(!subdep.error){
			$.each(subdep, function(i,n){
				op +="<option value="+n.id+">"+n.name+"</option>";
			});
		}
		$("#subdep").html(op);
		if(typeof(depopt_select)!="undefined"){
			$("#subdep").val(depopt_select.sid);
		}
		if(typeof(subdepid) != 'undefined')
		{
			$('select[name="subdep"]').val(subdepid);
		}
});
}
function getParentDep(){
	$.post("/aj_staff.php?action=getpardep","",function(rs){
		var pardep = eval("("+rs+")");
		var op = "<option value=-1>大部门</option>";
		if(!pardep.error){
			$.each(pardep, function(i,n){
				op +="<option value="+n.id+">"+n.name+"</option>";
			});
		}
		$("#parentdep").html("");
		$("#parentdep").html(op);
		if(typeof(depopt_select)!="undefined"){
			$("#parentdep").val(depopt_select.pid);
			getSubDep(depopt_select.pid);
		}
		if(typeof(parentdep) != 'undefined')
		{
			$('select[name="parentdep"]').val(parentdep);
		}
	});
}
$(document).ready(function(){list_admin_init();});
